<template>
  <div class="dashboard-editor-container">
    <el-row :gutter="40" class="panel-group">
      <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
        <div class="card-panel" @click="handleSetLineChartData('newVisitis')">
          <div class="card-panel-icon-wrapper icon-people">
            <svg-icon icon-class="peoples" class-name="card-panel-icon" />
          </div>
          <div class="card-panel-description">
            <div class="card-panel-text">IP城域网</div>
            <count-to :start-val="0" :end-val="show_total_ip_area" :duration="2600" class="card-panel-num" />
          </div>
        </div>
      </el-col>
      <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
        <div class="card-panel" @click="handleSetLineChartData('messages')">
          <div class="card-panel-icon-wrapper icon-message">
            <svg-icon icon-class="message" class-name="card-panel-icon" />
          </div>
          <div class="card-panel-description">
            <div class="card-panel-text">私网</div>
            <count-to :start-val="0" :end-val="show_total_private_net" :duration="3000" class="card-panel-num" />
          </div>
        </div>
      </el-col>
      <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
        <div class="card-panel" @click="handleSetLineChartData('purchases')">
          <div class="card-panel-icon-wrapper icon-money">
            <svg-icon icon-class="excel" class-name="card-panel-icon" />
          </div>
          <div class="card-panel-description">
            <div class="card-panel-text">DCN</div>
            <count-to :start-val="0" :end-val="show_total_dcn" :duration="3200" class="card-panel-num" />
          </div>
        </div>
      </el-col>
      <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
        <div class="card-panel" @click="handleSetLineChartData('shoppings')">
          <div class="card-panel-icon-wrapper icon-shopping">
            <svg-icon icon-class="list" class-name="card-panel-icon" />
          </div>
          <div class="card-panel-description">
            <div class="card-panel-text">总计</div>
            <count-to :start-val="0" :end-val="
              show_total_dcn + show_total_ip_area + show_total_private_net
            " :duration="3600" class="card-panel-num" />
          </div>
        </div>
      </el-col>
    </el-row>

    <el-row :gutter="12">
      <el-col :span="8">
        <el-card shadow="hover" header="私网">
          <el-row :gutter="12">
            <el-col :span="6">
              <div class="ls-big-center">
                {{ show_idle_private_net }}
              </div>
              <div class="ls-small-center">未分配</div>
            </el-col>
            <el-col :span="6">
              <div class="ls-big-center">
                {{ show_use_private_net }}
              </div>
              <div class="ls-small-center">已分配</div>
            </el-col>
            <el-col :span="6">
              <div class="ls-big-center">
                {{ show_use_off_private_net }}
              </div>
              <div class="ls-small-center">未使用</div>
            </el-col>
            <el-col :span="6">
              <div class="ls-big-center">
                {{ show_use_on_private_net }}
              </div>
              <div class="ls-small-center">已使用</div>
            </el-col>
          </el-row>
        </el-card>
      </el-col>
      <el-col :span="8">
        <el-card shadow="hover" header="ip城域网">
          <el-row :gutter="12">
            <el-col :span="6">
              <div class="ls-big-center">
                {{ show_idle_ip_area }}
              </div>
              <div class="ls-small-center">未分配</div>
            </el-col>
            <el-col :span="6">
              <div class="ls-big-center">
                {{ show_use_ip_area }}
              </div>
              <div class="ls-small-center">已分配</div>
            </el-col>
            <el-col :span="6">
              <div class="ls-big-center">
                {{ show_use_off_ip_area }}
              </div>
              <div class="ls-small-center">未使用</div>
            </el-col>
            <el-col :span="6">
              <div class="ls-big-center">
                {{ show_use_on_ip_area }}
              </div>
              <div class="ls-small-center">已使用</div>
            </el-col>
          </el-row>
        </el-card>
      </el-col>
      <el-col :span="8">
        <el-card shadow="hover" header="DCN模块">
          <el-row :gutter="12">
            <el-col :span="6">
              <div class="ls-big-center">
                {{ show_idle_dcn }}
              </div>
              <div class="ls-small-center">未分配</div>
            </el-col>
            <el-col :span="6">
              <div class="ls-big-center">
                {{ show_use_dcn }}
              </div>
              <div class="ls-small-center">已分配</div>
            </el-col>
            <el-col :span="6">
              <div class="ls-big-center">
                {{ show_use_off_dcn }}
              </div>
              <div class="ls-small-center">未使用</div>
            </el-col>
            <el-col :span="6">
              <div class="ls-big-center">
                {{ show_use_on_dcn }}
              </div>
              <div class="ls-small-center">已使用</div>
            </el-col>
          </el-row>
        </el-card>
      </el-col>
    </el-row>

    <el-row style="
        background: #fff;
        padding: 16px 16px 0;
        margin-bottom: 32px;
        margin-top: 50px;
      ">
      <div class="chart" style="height: 700px; width: 100%" ref="citychart"></div>
    </el-row>
  </div>
</template>

<script>
import CountTo from "vue-count-to";
import request from "@/utils/request";
import echarts from "echarts";
require("echarts/theme/macarons"); // echarts theme
import resize from "./dashboard/mixins/resize.js";

export default {
  name: "Index",
  mixins: [resize],
  components: {
    CountTo,
  },
  mounted() {
    this.getIndexsegment().then((obj) => {
      this.show_total_ip_area = obj.show_total.ip_area;
      this.show_total_private_net = obj.show_total.private_net;
      this.show_total_dcn = obj.show_total.dcn;

      this.show_idle_ip_area = obj.show_idle.ip_area;
      if (this.show_idle_ip_area < 0) {
        this.show_idle_ip_area = 0;
      }
      this.show_idle_private_net = obj.show_idle.private_net;
      this.show_idle_dcn = obj.show_idle.dcn;

      this.show_use_ip_area = obj.show_use.ip_area;
      this.show_use_private_net = obj.show_use.private_net;
      this.show_use_dcn = obj.show_use.dcn;

      this.show_use_on_ip_area = obj.show_use_on.ip_area;
      this.show_use_on_private_net = obj.show_use_on.private_net;
      this.show_use_on_dcn = obj.show_use_on.dcn;

      this.show_use_off_ip_area = obj.show_use_off.ip_area;
      this.show_use_off_private_net = obj.show_use_off.private_net;
      this.show_use_off_dcn = obj.show_use_off.dcn;

      for (let x in obj.show_total_city) {
        this.show_total_city.push(obj.show_total_city[x]);
      }
      for (let x in obj.show_use_city) {
        this.show_use_city.push(obj.show_use_city[x]);
      }
      this.$nextTick(() => {
        this.initChart();
      });
    });
  },
  data() {
    return {
      show_total_ip_area: 0,
      show_total_private_net: 0,
      show_total_dcn: 0,
      show_idle_ip_area: 0,
      show_idle_private_net: 0,
      show_idle_dcn: 0,
      show_use_ip_area: 0,
      show_use_private_net: 0,
      show_use_dcn: 0,
      show_use_on_ip_area: 0,
      show_use_on_private_net: 0,
      show_use_on_dcn: 0,
      show_use_off_ip_area: 0,
      show_use_off_private_net: 0,
      show_use_off_dcn: 0,
      show_total_city: [],
      show_use_city: [],
      chart: null,
    };
  },
  methods: {
    getIndexsegment() {
      return request({
        url: "/ipmanagement/indexsegment/show",
        method: "get",
      });
    },

    initChart() {
      this.chart = echarts.init(this.$refs["citychart"], "macarons");
      this.setNewOptions();
    },
    setNewOptions() {
      let option = {
        title: {
          text: "地市ip分布",
        },
        tooltip: {
          trigger: "axis",
          axisPointer: {
            type: "cross",
            label: {
              backgroundColor: "#6a7985",
            },
          },
        },
        legend: {
          data: ["省分配", "地市使用"],
        },
        toolbox: {
          feature: {
            saveAsImage: {},
          },
        },
        grid: {
          left: "3%",
          right: "4%",
          bottom: "3%",
          containLabel: true,
        },
        xAxis: [
          {
            type: "category",
            boundaryGap: false,
            data: [
              "沈阳",
              "大连",
              "鞍山",
              "铁岭",
              "本溪",
              "丹东",
              "锦州",
              "抚顺",
              "营口",
              "阜新",
              "辽阳",
              "盘锦",
              "朝阳",
              "葫芦岛",
              "省本级",
            ],
          },
        ],
        yAxis: [
          {
            type: "value",
          },
        ],
        series: [
          {
            name: "省分配",
            type: "line",
            stack: "Total",
            areaStyle: {},
            emphasis: {
              focus: "series",
            },
            data: this.show_total_city,
          },
          {
            name: "地市使用",
            type: "line",
            stack: "Total",
            areaStyle: {},
            emphasis: {
              focus: "series",
            },
            data: this.show_use_city,
          },
        ],
      };
      this.chart.setOption(option);
    },
  },
};
</script>

<style lang="scss" scoped>
.dashboard-editor-container {
  padding: 32px;
  background-color: rgb(240, 242, 245);
  position: relative;

  .chart-wrapper {
    background: #fff;
    padding: 16px 16px 0;
    margin-bottom: 32px;
  }
}

@media (max-width: 1024px) {
  .chart-wrapper {
    padding: 8px;
  }
}

.panel-group {
  margin-top: 18px;

  .card-panel-col {
    margin-bottom: 32px;
  }

  .card-panel {
    height: 108px;
    cursor: pointer;
    font-size: 12px;
    position: relative;
    overflow: hidden;
    color: #666;
    background: #fff;
    box-shadow: 4px 4px 40px rgba(0, 0, 0, 0.05);
    border-color: rgba(0, 0, 0, 0.05);

    &:hover {
      .card-panel-icon-wrapper {
        color: #fff;
      }

      .icon-people {
        background: #40c9c6;
      }

      .icon-message {
        background: #36a3f7;
      }

      .icon-money {
        background: #f4516c;
      }

      .icon-shopping {
        background: #34bfa3;
      }
    }

    .icon-people {
      color: #40c9c6;
    }

    .icon-message {
      color: #36a3f7;
    }

    .icon-money {
      color: #f4516c;
    }

    .icon-shopping {
      color: #34bfa3;
    }

    .card-panel-icon-wrapper {
      float: left;
      margin: 14px 0 0 14px;
      padding: 16px;
      transition: all 0.38s ease-out;
      border-radius: 6px;
    }

    .card-panel-icon {
      float: left;
      font-size: 48px;
    }

    .card-panel-description {
      float: right;
      font-weight: bold;
      margin: 26px;
      margin-left: 0px;

      .card-panel-text {
        line-height: 18px;
        color: rgba(0, 0, 0, 0.45);
        font-size: 16px;
        margin-bottom: 12px;
      }

      .card-panel-num {
        font-size: 20px;
      }
    }
  }
}

@media (max-width: 550px) {
  .card-panel-description {
    display: none;
  }

  .card-panel-icon-wrapper {
    float: none !important;
    width: 100%;
    height: 100%;
    margin: 0 !important;

    .svg-icon {
      display: block;
      margin: 14px auto !important;
      float: none !important;
    }
  }
}

.ls-big-center {
  text-align: center;
  font-size: large;
  font-weight: bold;
  color: #36a3f7;
}

.ls-small-center {
  text-align: center;
  font-size: small;
  padding-top: 10px;
}
</style>
